﻿@inject IStringLocalizer<DropdownRadio> Localizer

<div class="row g-3">
    <div class="col-12">
        <RadioList TValue="SelectedItem" Items="@RadioItems" OnSelectedChanged="@OnRadioItemChanged">
        </RadioList>
    </div>
    <div class="col-12">
        <Dropdown TValue="string" Items="@RadioDropDownItems">
        </Dropdown>
    </div>
</div>
@code {
    private List<SelectedItem> RadioItems { get; set; } = new List<SelectedItem>();

    private List<SelectedItem> RadioDropDownItems { get; set; } = new List<SelectedItem>();

    /// <summary>
    /// OnInitialized
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        RadioDropDownItems = new List<SelectedItem>
        {
            new SelectedItem("1", Localizer["Item1"]) { Active = true },
            new SelectedItem("2", Localizer["Item2"]),
            new SelectedItem("3", Localizer["Item3"])
        };

        RadioItems = new List<SelectedItem>
        {
            new SelectedItem("1", Localizer["Item1"]) { Active = true },
            new SelectedItem("2", Localizer["Item2"])
        };
    }

    /// <summary>
    /// OnRadioItemChanged
    /// </summary>
    /// <param name="values"></param>
    /// <param name="item"></param>
    /// <returns></returns>
    private Task OnRadioItemChanged(IEnumerable<SelectedItem> values, SelectedItem item)
    {
        RadioDropDownItems.Add(new SelectedItem($"{RadioDropDownItems.Count + 1}", $"{Localizer["City"]} {RadioDropDownItems.Count}"));
        StateHasChanged();
        return Task.CompletedTask;
    }
}
